package com.example.vehicle.Performance;

import com.example.vehicle.Utils.HttpClientUtil;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @name: QueryVehicles
 * @description: 仿真测试-查询。
 * @author: Lulu Zhao
 **/
public class QueryVehicles implements Runnable {
    static double totalTime;

    /**
     * @name: run
     * @description: runnable接口run函数。
     * @params: []
     * @return: void
     * @author: Lulu Zhao
     */
    @Override
    public void run() {
        Map<String, String> param = new HashMap<>();
        param.put("vehicleId", "fff8f6d4d4b848a18be8bc159d2cdfc6");
        double startTime = System.nanoTime();
        HttpClientUtil.doGet("http://localhost:8080/vehcc/queryVehicleById", param);
        double endTime = System.nanoTime();
        totalTime = endTime - startTime;
        try {
            String registerFileName = "src/query.txt";
            File registerFile = new File(registerFileName);
            FileWriter fileWriter = new FileWriter(registerFile, true);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            bufferedWriter.write(totalTime / 1000000 + "\n");
            bufferedWriter.close();
            fileWriter.close();
            System.out.println("查询操作" + totalTime / 1000000 + "ms");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
